package model

import (
	"time"
)

type BlogSettings struct {
	Id                  int    `db:"id"`
	Sitename            string `db:"sitename"`
	SiteDescription     string `db:"site_description"`
	SiteSeoDescription  string `db:"site_seo_description"`
	SiteKeywords        string `db:"site_keywords"`
	ArticleSubLength    int    `db:"article_sub_length"`
	SidebarArticleCount int    `db:"sidebar_article_count"`
	SidebarCommentCount int    `db:"sidebar_comment_count"`
	ArticleCommentCount int    `db:"article_comment_count"`
	ShowGoogleAdSense   bool   `db:"show_google_adsense"`
	GoogleAdsenseCodes  string `db:"google_adsense_codes"`
	OpenSiteComment     bool   `db:"open_site_comment"`
	Beiancode           string `db:"beiancode"`
	Analyticscode       string `db:"analyticscode"`
	ShowGonganCode      bool   `db:"show_gongan_code"`
	GonganBeiancode     string `db:"gongan_beiancode"`
}

func (b BlogSettings) TableName() string {
	return "blog_blogsettings"
}

type BlogLinks struct {
	Id          int       `db:"id"`
	Name        string    `db:"name"`
	Link        string    `db:"link"`
	Sequence    int       `db:"sequence"`
	IsEnable    bool      `db:"is_enable"`
	ShowType    string    `db:"show_type"`
	CreatedTime time.Time `db:"created_time"`
	LastModTime time.Time `db:"last_mod_time"`
}

func (b *BlogLinks) TableName() string {
	return "blog_links"
}

type BlogSidebar struct {
	Id          int       `db:"id"`
	Name        string    `db:"name"`
	Content     string    `db:"content"`
	Sequence    int       `db:"sequence"`
	IsEnable    bool      `db:"is_enable"`
	CreatedTime time.Time `db:"created_time"`
	LastModTime time.Time `db:"last_mod_time"`
}

func (b *BlogSidebar) TableName() string {
	return "blog_sidebar"
}

type BlogTag struct {
	Id          int       `db:"id" json:"id"`
	Name        string    `db:"name" json:"name"`
	Slug        string    `db:"slug" json:"slug"`
	CreatedTime time.Time `db:"created_time" json:"created_time"`
	LastModTime time.Time `db:"last_mod_time" json:"last_mod_time"`
}

func (b BlogTag) TableName() string {
	return "blog_tag"
}

type BlogCategory struct {
	Id               int       `db:"id" json:"id"`
	CreatedTime      time.Time `db:"created_time" json:"created_time"`
	LastModTime      time.Time `db:"last_mod_time" json:"last_mod_time"`
	Name             string    `db:"name" json:"name"`
	Slug             string    `db:"slug" json:"slug"`
	Index            int       `db:"index" json:"index"`
	ParentCategoryId *int      `db:"parent_category_id" json:"parent_category_id"`
}

func (b BlogCategory) TableName() string {
	return "blog_category"
}

// 文章状态
type ArticleStatus string

const (
	StatusDraft     ArticleStatus = "d" // 草稿
	StatusPublished ArticleStatus = "p" // 发表
)

// 评论状态
type CommentStatus string

const (
	CommentOpen  CommentStatus = "o" // 打开
	CommentClose CommentStatus = "c" // 关闭
)

// 文章类型
type ArticleType string

const (
	TypeArticle ArticleType = "a" // 文章
	TypePage    ArticleType = "p" // 页面
)

type BlogArticle struct {
	Id            int           `db:"id" json:"id"`
	CreatedTime   time.Time     `db:"created_time" json:"created_time"`
	LastModTime   time.Time     `db:"last_mod_time" json:"last_mod_time"`
	Title         string        `db:"title" json:"title"`
	Body          string        `db:"body" json:"body"`
	PubTime       time.Time     `db:"pub_time" json:"pub_time"`
	Status        ArticleStatus `db:"status" json:"status"`
	CommentStatus CommentStatus `db:"comment_status" json:"comment_status"`
	Type          ArticleType   `db:"type" json:"type"`
	Views         int           `db:"views" json:"views"`
	ArticleOrder  int           `db:"article_order" json:"article_order"`
	ShowToc       bool          `db:"show_toc" json:"show_toc"`
	AuthorId      int           `db:"author_id" json:"author_id"`
	CategoryId    int           `db:"category_id" json:"category_id"`
}

type BlogArticleWithTags struct {
	BlogArticle
	Tags string `db:"tags" json:"tags"`
}

type BlogArticleDetail struct {
	BlogArticle
	AuthorUsername string `db:"author_username" json:"author_username"`
	CategoryName   string `db:"category_name" json:"category_name"`
	Tags           string `db:"tags" json:"tags"`
}

type BlogArticleWithTagDetail struct {
	BlogArticle
	AuthorUsername string       `db:"author_username" json:"author_username"`
	Tags           []BlogTag    `db:"tags" json:"tags"`
	CategoryDetail BlogCategory `db:"category_detail" json:"category_detail"`
}

func (b BlogArticle) TableName() string {
	return "blog_article"
}

type BlogArticleTags struct {
	Id        int `db:"id"`
	ArticleId int `db:"article_id"`
	TagId     int `db:"tag_id"`
}

func (b BlogArticleTags) TableName() string {
	return "blog_article_tags"
}
